package com.zcz.umengpush.util;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 王卫帅
 */
public class Util {
    /**
     * 解析HttpServletRequest request 的参数
     * @param request
     * @return
     * @throws IOException
     */
    public static byte[] getRequestPostBytes(HttpServletRequest request) throws IOException {
        int contentLength = request.getContentLength();
        if(contentLength<0){
            return null;
        }
        byte[] buffer = new byte[contentLength];
        for(int i = 0;i<contentLength;){
            int readlen = request.getInputStream().read(buffer,i,contentLength - i);
            if(readlen == -1){
                break;
            }
            i += readlen;
        }
        return buffer;
    }
}
